<template>
    <div>
        名称:
        <input type="text" v-model="vor.name" >
        会员等级:
        <select v-model="vor.id">
                            <option value="">请选择</option>
                            <option :value="o.hId" v-for="o in fana">{{ o.hName }}</option>
                        </select>
                        <input type="button" value="查询" @click="Show" >
        <table class="table table-bordered ">
            <thead>
                <tr>
                    <td>会员编号</td>
                    <td>姓名</td>
                    <td>性别</td>
                    <td>手机号</td>
                    <td>会员级别</td>
                    <td>日期</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
                <tr v-for="o in info">
                    <td>{{ o.number }}</td>
                    <td>{{ o.wName }}</td>
                    <td>{{ o.sex==1?"男":"女" }}</td>
                    <td>{{ o.phone }}</td>
                    <td>{{ o.hName }}</td>
                    <td>{{ moment(o.date).format("yyyy-YY-DD")  }}</td>
                    <td>{{ o.state==1?"启用":"禁用" }}</td>
                    <td><input type="button" value="删除"  @click="Delete(o.wId)" >
                        <input type="button" value="禁用" v-if="o.state==1" @click="updata(o.wId,0)" >
                        <input type="button" value="启用" v-if="o.state==0" @click="updata(o.wId,1)" >
                        <input type="button" value="修改"  @click="Fand(o.wId)" >
                        </td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { isLeftHandSideExpression } from 'typescript';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';

const router=useRouter();

let info:any=ref([]);

let vor:any=ref({
    name:'',
    id:''
});




let fana:any=ref([]);

onMounted(()=>{
    Show();
    List();
} )

const Fand=(wId:any)=>{
    router.push({
        path:'/fandw',
        query:{
            id:wId
        }
    })
}

const Delete=(wId:any)=>{
    let f=confirm("要修改吗");
    if(f){
        axios({
        url:'https://localhost:7033/api/User/Delete',
        method:'post',
        params:{
            id:wId
        }
    })

    .then((res)=>{
        console.log(res);
        if(res.data>0)
    {
        alert("删除成功");
        Show();
    }
    else
    {
        alert("删除失败");
    }
    })
    }                                                                                                                                                           
    
}

const Show=()=>{
    axios({
        url:'https://localhost:7033/api/User/Showw',
        method:'get',
        params:vor.value
    })

    .then((res)=>{
        info.value=res.data
    })
}


const List=()=>{
    axios({
        url:'https://localhost:7033/api/User/ListW',
        method:'get'
    })
    .then((res)=>{
        console.log(res);
        fana.value=res.data
    })
}


const updata=(wId:any,state:any)=>{
    let f=confirm("要修改吗");
    if(f )
{
    axios({
        url:'https://localhost:7033/api/User/UpdataW',
        method:'post',
        params:{
            id:wId,
            state:state
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0 )
    {
        alert("成功");
        Show();
    }
    else
    {
        alert("失败");
    }
    })
}
    
    
}


</script>

<style scoped>

</style>